home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / rxdoscmd.zip / RXDOSDIR.ASM < prev    next >
Assembly Source File  |  1993-06-06  |  36KB  |  847 lines

  1.         TITLE   'Dir - RxDOS Command Shell Dir Function'
  2.         PAGE 59, 132
  3.         .LALL
  4.  
  5.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  6.         ;  RxDOS Command Shell Dir                                      ;
  7.         ;...............................................................;
  8.  
  9.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  10.         ;  Real Time Dos                                                ;
  11.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  12.         ;                                                               ;
  13.         ;  This material  was created as a published version  of a DOS  ;
  14.         ;  equivalent product.   This program  logically  functions in  ;
  15.         ;  the same way as  MSDOS functions and it  is  internal  data  ;
  16.         ;  structure compliant with MSDOS 5.0                           ;
  17.         ;                                                               ;
  18.         ;  This product is distributed  AS IS and contains no warranty  ;
  19.         ;  whatsoever,   including  warranty  of   merchantability  or  ;
  20.         ;  fitness for a particular purpose.                            ;
  21.         ;                                                               ;
  22.         ;                                                               ;
  23.         ;  (c) Copyright 1990, 1992. Api Software and Mike Podanoffsky  ;
  24.         ;      All Rights Reserved Worldwide.                           ;
  25.         ;                                                               ;
  26.         ;  This product is protected under copyright laws and  may not  ;
  27.         ;  be reproduced  in whole  or in part, in any form  or media,  ;
  28.         ;  included but not limited to source listing, facimilie, data  ;
  29.         ;  transmission, cd-rom, or  floppy disk without the expressed  ;
  30.         ;  written consent of the author.                               ;
  31.         ;                                                               ;
  32.         ;  Licence for distribution in commercial use:                  ;
  33.         ;                                                               ;
  34.         ;  Api Software                                                 ;
  35.         ;  12 South Walker Street                                       ;
  36.         ;  Lowell,  MA   01851                                          ;
  37.         ;  508/ 454-4961.                                               ;
  38.         ;                                                               ;
  39.         ;...............................................................;
  40.  
  41.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  42.         ;  RxDOS Command Shell                                          ;
  43.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  44.         ;                                                               ;
  45.         ;  Programmer's Notes:                                          ;
  46.         ;                                                               ;
  47.         ;  Command Shell consists of  two parts bound  together into a  ;
  48.         ;  single executable load.  There  exists  a  single  resident  ;
  49.         ;  command shell which is accessible by an Int 2Eh.             ;
  50.         ;                                                               ;
  51.         ;...............................................................;
  52.  
  53.         include rxdosmac.asm
  54.         include rxdosdef.asm
  55.         include rxdoscin.asm
  56.  
  57.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  58.         ;  RxDOS Command Shell                                          ;
  59.         ;...............................................................;
  60.  
  61. RxDOSCMD SEGMENT PUBLIC 'CODE'
  62.          assume cs:RxDOSCMD, ds:RxDOSCMD, es:RxDOSCMD, ss:RxDOSCMD
  63.  
  64.         public _Dir
  65.         public _splitpath
  66.         public _makePath
  67.  
  68.         extrn CheckOptOneArg                            : near
  69.         extrn CmndError_InvalidDrive                    : near
  70.         extrn CmndError_NoFilesFound                    : near
  71.         extrn CRLF                                      : near
  72.         extrn DisplayLine                               : near
  73.         extrn DisplayErrorMessage                       : near
  74.         extrn PreProcessCmndLine                        : near
  75.         extrn RxDOS_AllFiles                            : near
  76.         extrn setPagingMode                             : near
  77.         extrn _AppendPathName                           : near
  78.         extrn _CopyString                               : near
  79.  
  80.         extrn _DirAttribSwitch                          : near
  81.         extrn _DirBareSwitch                            : near
  82.         extrn _DirLowerCaseSwitch                       : near
  83.         extrn _DirOrderSwitch                           : near
  84.         extrn _DirPauseSwitch                           : near
  85.         extrn _DirSubDirSwitch                          : near
  86.         extrn _DirSwitches                              : near
  87.         extrn _DirWideSwitch                            : near
  88.         extrn _Dir_DirectoryOf                          : near
  89.         extrn _Dir_DirEntry                             : near
  90.         extrn _Dir_FileEntry                            : near
  91.         extrn _Dir_Files                                : near
  92.         extrn _Dir_NoVolumeLabel                        : near
  93.         extrn _Dir_VolumeLabel                          : near
  94.         extrn _Dir_VolumeSerialNumber                   : near
  95.  
  96.         extrn RxDOS_DTA                                 : near
  97.         extrn _lowerCase                                : near
  98.         extrn _lowerCaseString                          : near
  99.         extrn _endofString                              : near
  100.         extrn _sprintf                                  : near
  101.         extrn returnVolumeName                          : near
  102.  
  103.  
  104.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  105.         ;  Dir Time To Ascii (USA Format)                               ;
  106.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  107.         ;                                                               ;
  108.         ;  Input:                                                       ;
  109.         ;   ax     time value                                           ;
  110.         ;   di     address to display time of day                       ;
  111.         ;                                                               ;
  112.         ;...............................................................;
  113.  
  114.  
  115. _dirTimeToAscii:
  116.  
  117.         push di
  118.         
  119.         push ax
  120.         mov ch, 'a'
  121.         mov cl, 11                              ; ch = 0
  122.         shr ax, cl                              ; hours
  123.         cmp ax, 13                              ; 1 pm or greater ?
  124.         jc _dirTimeToAscii_08                   ; no -->
  125.  
  126.         sub ax, 12                              ; 1 pm or greater
  127.         mov ch, 'p'                             ; set pm flag
  128.         
  129. _dirTimeToAscii_08:
  130.         mov cl, 10
  131.         div cl
  132.         or ax, '00'                             ; conv to ascii
  133.         stosw
  134.  
  135.         mov al,':'
  136.         stosb
  137.  
  138.         pop ax
  139.         mov cl, 5
  140.         shr ax, cl                              ; minutes
  141.         and ax, 00111111b                       ; mask off hours
  142.         
  143.         mov cl, 10
  144.         div cl
  145.         or ax, '00'                             ; conv to ascii
  146.         stosw
  147.  
  148.         xor ah, ah
  149.         mov al, ch
  150.         stosw
  151.  
  152.         pop di
  153.         cmp byte ptr [ di ], '0'
  154.         jnz _dirTimeToAscii_12
  155.         mov byte ptr [ di ], ' '
  156.  
  157. _dirTimeToAscii_12:
  158.         ret
  159.  
  160.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  161.         ;  Dir Date To Ascii (USA Format)                               ;
  162.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  163.         ;                                                               ;
  164.         ;  Input:                                                       ;
  165.         ;   ax     date value                                           ;
  166.         ;   di     address to display date of day                       ;
  167.         ;                                                               ;
  168.         ;...............................................................;
  169.  
  170. _dirDateToAscii:
  171.  
  172.         push di
  173.         push ax
  174.         mov cl,  5
  175.         shr ax, cl                              ; Month
  176.         and ax, 00001111b                       ; mask off year 
  177.  
  178.         mov cl, 10
  179.         div cl
  180.         or ax, '00'                             ; conv to ascii
  181.         stosw
  182.  
  183.         mov al,'-'
  184.         stosb
  185.  
  186.         pop ax
  187.         push ax
  188.         and ax, 00011111b                       ; mask off everything but day
  189.         
  190.         mov cl, 10
  191.         div cl
  192.         or ax, '00'                             ; conv to ascii
  193.         stosw
  194.  
  195.         mov al,'-'
  196.         stosb
  197.  
  198.         pop ax
  199.         mov cl,  9
  200.         shr ax, cl                              ; Year
  201.         and ax, 01111111b                       ; mask
  202.         add ax, 80                              ; 80 plus
  203.         cmp ax, 100                             ; past year 2000 ?
  204.         jc _dirDateToAscii_08                   ; no need to adjust -->
  205.  
  206.         sub ax, 100                             ; 2000 plus
  207.  
  208. _dirDateToAscii_08:
  209.         mov cl, 10
  210.         div cl
  211.         or ax, '00'                             ; conv to ascii
  212.         stosw
  213.  
  214.         xor al, al
  215.         stosb
  216.  
  217.         pop di
  218.         cmp byte ptr [ di ], '0'
  219.         jnz _dirDateToAscii_12
  220.         mov byte ptr [ di ], ' '
  221.  
  222. _dirDateToAscii_12:
  223.         ret
  224.  
  225.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  226.         ;  Split Path                                                   ;
  227.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  228.         ;                                                               ;
  229.         ;  Usage:                                                       ;
  230.         ;   si     points to filename to split                          ;
  231.         ;   di     points to expanded name area                         ;
  232.         ;...............................................................;
  233.  
  234. _splitpath:
  235.  
  236.         Entry
  237.         
  238.         def _source, si
  239.         def _expandedname, di
  240.         def _extension
  241.         def _wildchars, 0000
  242.  
  243.         push di
  244.         xor ax, ax
  245.         mov cx, sizeExpandedName
  246.         rep stosb                                       ; clear expand area
  247.         pop di
  248.  
  249. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  250. ;  examine/ extract drive letter from path
  251. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  252.  
  253.         cmp byte ptr [ si+1 ],':'                       ; test for drive letter
  254.         jnz _splitpath_08                               ; no drive letter entered -->
  255.  
  256.         mov al, byte ptr [ si ]
  257.         mov byte ptr [ expDrive ][ di ], al             ; isolate drive letter
  258.         inc si
  259.         inc si
  260.  
  261. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  262. ;  scan string through entire path until extension, if any.
  263. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  264.  
  265. _splitpath_08:
  266.         xor ax, ax                                      ; prev character
  267.         mov dx, si
  268.         push si
  269.  
  270. _splitpath_12:
  271.         xor cx, cx                                      ; last . separator, if any
  272.  
  273. _splitpath_16:
  274.         mov ah, al                                      ; prev character
  275.         mov al, byte ptr [ si ]
  276.         inc si
  277.         or al, al                                       ; end of string ?
  278.         jz _splitpath_28                                ; if yes -->
  279.         cmp al, '/'                                     ; path separator ?
  280.         jz _splitpath_24                                ; if yes -->
  281.         cmp al, '\'                                     ; path separator ?
  282.         jz _splitpath_24                                ; if yes -->
  283.  
  284.         cmp al, '?'                                     ; wild character ?
  285.         jz _splitpath_26                                ; if yes -->
  286.         cmp al, '*'                                     ; wild character ?
  287.         jz _splitpath_26                                ; if yes -->
  288.  
  289.         cmp al, '.'                                     ; extension separator ?
  290.         jnz _splitpath_16
  291.  
  292.         cmp ah, '.'                                     ; previous also ..
  293.         jz _splitpath_12                                ; yes, ignore -->
  294.         mov cx, si                                      ; save location of extension
  295.         dec cx                                          ; must save dot position
  296.         jmp _splitpath_16                               ; continue scanning -->
  297.  
  298. _splitpath_24:
  299.         mov dx, si
  300.         jmp _splitpath_16
  301.  
  302. _splitpath_26:
  303.         mov byte ptr [ _wildchars ][ bp ], 1
  304.         jmp _splitpath_16
  305.  
  306. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  307. ;  at end of scan, see if path defined
  308. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  309.  
  310. _splitpath_28:
  311.         pop si                                          ; start of path
  312.         storarg _extension, cx                          ; save pointer to extension
  313.         or dx, dx                                       ; path defined (\ in string ?)
  314.         jz _splitpath_38                                ; no path defined -->
  315.  
  316.         mov cx, dx
  317.         sub cx, si                                      ; length of path string
  318.         cmp cx, size expPath                            ; greater than expPath ?
  319.         jle _splitpath_30                               ; no -->
  320.         mov cx, (size expPath) - 1                      ; max size
  321.  
  322. _splitpath_30:
  323.         getarg di, _expandedname
  324.         lea di, offset [ expPath ][ di ]
  325.         rep movsb                                       ; copy path
  326.  
  327. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  328. ;  copy filename
  329. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  330.  
  331. _splitpath_38:
  332.         getarg di, _expandedname
  333.         lea di, offset [ expFilename ][ di ]
  334.         mov cx, (size expFilename) - 1
  335.  
  336.         mov si, dx                                      ; get start of filename
  337.         or si, si                                       ; no filename ?
  338.         jz _splitpath_48                                ; no -->
  339.  
  340. _splitpath_40:
  341.         lodsb                                           ; get character
  342.         or al, al                                       ; if null, no extension -->
  343.         jz _splitpath_60
  344.         cmp al, '.'                                     ; if period
  345.         jz _splitpath_48                                ; we have extension -->
  346.  
  347.         stosb
  348.         loop _splitpath_40
  349.  
  350. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  351. ;  copy extension
  352. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  353.  
  354. _splitpath_48:
  355.         getarg di, _expandedname
  356.         lea di, offset [ expExtension ][ di ]
  357.         mov cx, (size expExtension) - 1
  358.         getarg si, _extension         
  359.         or si, si                                       ; no filename ?
  360.         jz _splitpath_60                                ; no -->
  361.  
  362. _splitpath_50:
  363.         lodsb                                           ; get character
  364.         or al, al                                       ; if null, no extension -->
  365.         jz _splitpath_60
  366.  
  367.         stosb
  368.         loop _splitpath_50
  369.  
  370. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  371. ;  done
  372. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  373.  
  374. _splitpath_60:
  375.         mov al, byte ptr [ _wildchars ][ bp ]
  376.         or al, al
  377.         Return
  378.  
  379.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  380.         ;  Make Path                                                    ;
  381.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  382.         ;                                                               ;
  383.         ;  Usage:                                                       ;
  384.         ;   si     points to expanded name area                         ;
  385.         ;   di     points to filename to build                          ;
  386.         ;...............................................................;
  387.  
  388. _makePath:
  389.  
  390.         push si
  391.         push di
  392.         mov dx, si
  393.         mov byte ptr [ di ], 00
  394.  
  395. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  396. ;  insert drive  
  397. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  398.  
  399.         lea bx, offset [ expDrive ][ si ]
  400.         mov al, byte ptr [ bx ]
  401.         or al, al                                       ; drive available ?
  402.         jz _makePath_08                                 ; no -->
  403.  
  404.         mov ah, ':'
  405.         stosw                                           ; store drive
  406.         mov byte ptr [ di ], 00
  407.  
  408. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  409. ;  insert path
  410. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  411.  
  412. _makePath_08:
  413.         lea si, offset [ expPath ][ si ]
  414.         mov al, byte ptr [ si ]
  415.         or al, al                                       ; path available ?
  416.         jz _makePath_16                                 ; no -->
  417.  
  418.         call _CopyString                                ; copy path to output
  419.         dec di                                          ; backup over null term
  420.         cmp byte ptr [ di-1 ], '\'                      ; path ended in \ ?
  421.         jz _makePath_16                                 ; no -->
  422.  
  423.         mov ax, '\'
  424.         stosb                                           ; add \
  425.         mov byte ptr [ di ], 00
  426.  
  427. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  428. ;  insert filename
  429. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  430.  
  431. _makePath_16:
  432.         mov si, dx
  433.         lea si, offset [ expFilename ][ si ]
  434.         mov al, byte ptr [ si ]
  435.         or al, al                                       ; filename available ?
  436.         jz _makePath_24                                 ; no -->
  437.  
  438.         call _CopyString                                ; copy filename to output
  439.         dec di                                          ; backup over null term
  440.  
  441. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  442. ;  insert extension
  443. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  444.  
  445. _makePath_24:
  446.         mov si, dx
  447.         lea si, offset [ expExtension ][ si ]
  448.         mov al, byte ptr [ si ]
  449.         or al, al                                       ; filename available ?
  450.         jz _makePath_32                                 ; no -->
  451.  
  452.         call _CopyString                                ; copy filename to output
  453.  
  454. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  455. ;  return
  456. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  457.  
  458. _makePath_32:
  459.         pop di
  460.         pop si
  461.         ret
  462.  
  463.         ;''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
  464.         ;  Directory                                                    ;
  465.         ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  466.         ;                                                               ;
  467.         ;  Usage:                                                       ;
  468.         ;   ss:di  Arg Array                                            ;
  469.         ;   ax     Number of arguments in array                         ;
  470.         ;...............................................................;
  471.  
  472. _Dir:
  473.  
  474.         Entry
  475.         def  _currdisk
  476.         def  _maxdisk
  477.         def  _filesread
  478.         def _extensionFlag
  479.         ddef _freespace
  480.         ddef _totalfilespace
  481.         def __argarray, di                              ; arg array
  482.  
  483.         defbytes _asciiFileTime, 20
  484.         defbytes _asciiFileDate, 20
  485.         defbytes _pathname, 128                         ; search pathname
  486.         defbytes _filename, 128                         ; search filename
  487.         defbytes _expandedname, sizeExpandedName
  488.         defbytes _printbuffer, 128
  489.  
  490.         xor ax, ax
  491.         mov word ptr [ _filesread ][ bp ], ax
  492.         mov word ptr [ _totalfilespace. _low  ][ bp ], ax
  493.         mov word ptr [ _totalfilespace. _high ][ bp ], ax
  494.  
  495.         mov cx, 0000                                    ; min args
  496.         mov dx, 0001                                    ; max args
  497.         mov bx, offset _DirSwitches                     ; dir switches
  498.         call PreProcessCmndLine                         ; process switches and args
  499.         ifc _dir_86                                     ; if error -->
  500.  
  501.         mov ax, word ptr [ _DirPauseSwitch. swFlags ]
  502.         call setPagingMode
  503.  
  504. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  505. ;  get current, max disks
  506. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  507.  
  508.         Int21 CurrentDisk                               ; get current disk
  509.         mov dl, al
  510.         inc al                                          ; a=1, ...
  511.         storarg _currdisk, ax                           ; save disk letter
  512.  
  513.         Int21 SelectDisk                                ; use select disk to get max
  514.         storarg _maxdisk, ax                            ; save max disk letter
  515.  
  516. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  517. ;  if no args, create a *.* arg
  518. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  519.  
  520.         mov di, word ptr [ __argarray ][ bp ]
  521.         mov si, word ptr [ di ]                         ; locate dir argument
  522.         or si, si                                       ; no name provided ?
  523.         jnz _dir_06                                     ; name provided -->
  524.         mov si, offset RxDOS_AllFiles                   ; dummy path 
  525.  
  526. _dir_06:
  527.         lea di, offset [ _pathname ][ bp ]
  528.         call _CopyString                                ; copy whatever was entered
  529.  
  530. _dir_08:
  531.         dec di                                          ; backup over null
  532.         cmp byte ptr [ di-1 ], ' '                      ; only entered drive and colon ?
  533.         jz _dir_08                                      ; no -->
  534.         cmp byte ptr [ di-1 ], ':'                      ; only entered drive and colon ?
  535.         jnz _dir_10                                     ; no -->
  536.  
  537.         mov si, offset RxDOS_AllFiles                   ; dummy path 
  538.         call _CopyString                                ; append all files
  539.  
  540. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  541. ;  is name a directory ?
  542. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  543.  
  544. _dir_10:
  545.         lea si, offset [ _pathname ][ bp ]
  546.         lea di, offset [ _expandedname ][ bp ]
  547.         call _splitpath
  548.  
  549.         mov al, byte ptr [ _expandedname. expExtension ][ bp ]
  550.         mov byte ptr [ _extensionFlag ][ bp ], al       ; save whether extension was ever present
  551.  
  552.         lea si, offset [ _pathname ][ bp ]
  553.         lea di, offset [ _filename ][ bp ]
  554.         mov word ptr [ di ], '\'                        ; init area
  555.         Int21 GetActualFileName                         ; expand name
  556.         jnc _dir_16                                     ; if valid -->
  557.         call _CopyString                                ; if error, pass original for further processing
  558.  
  559. _dir_16:
  560.         lea si, offset [ _filename ][ bp ]
  561.         lea di, offset [ _expandedname ][ bp ]
  562.         call _splitpath
  563.         jnz _dir_28                                     ; if wild characters found -->
  564.  
  565.         mov cx, ATTR_DIRECTORY
  566.         lea dx, offset [ _filename ][ bp ]
  567.         Int21 FindFirstFile                             ; locate file
  568.  
  569. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  570. ;  if . or .. handle special
  571. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  572.  
  573. _dir_20:
  574.         jc _dir_28                                      ; not found, try expanding -->
  575.  
  576.         test byte ptr [ RxDOS_DTA. findFileAttribute ], ATTR_DIRECTORY
  577.         jz _dir_28                                      ; if a directory, add \*.*  -->
  578.  
  579.         cmp byte ptr [ RxDOS_DTA. findFileName ], '.'
  580.         jnz _dir_22  
  581.  
  582.         Int21 FindNextFile                              ; locate next file
  583.         jmp _dir_20                                     ; see if also a dir -->
  584.  
  585. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  586. ;  if a directory name, change to include *.* for all files
  587. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  588.  
  589. _dir_22:
  590.         lea si, offset [ _expandedname. expFilename ][ bp ]
  591.         lea di, offset [ _expandedname. expPath     ][ bp ]
  592.         call _AppendPathName                            ; append path name
  593.  
  594.         lea si, offset [ _expandedname. expExtension ][ bp ]
  595.         call _CopyString                                ; append to path name
  596.  
  597.         mov byte ptr [ _expandedname. expExtension ][ bp ], 00
  598.  
  599.         mov si, offset [ RxDOS_AllFiles ]
  600.         lea di, offset [ _expandedname. expFilename ][ bp ]
  601.         call _CopyString
  602.         jmp _dir_36                                     ; if none, ok to makepath
  603.  
  604. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  605. ;  is name is not a directory
  606. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  607.  
  608. _dir_28:
  609.         lea di, offset [ _expandedname. expFilename ][ bp ]
  610.         cmp byte ptr [ di ], 00
  611.         jnz _dir_32
  612.         mov word ptr [ di ], '*'
  613.  
  614. _dir_32:
  615.         lea di, offset [ _expandedname. expExtension ][ bp ]
  616.         mov al, byte ptr [ _extensionFlag ][ bp ]       ; extension required 
  617.         or al, byte ptr [ di ]                          ; or extension provided
  618.         jnz _dir_36                                     ; if either -->
  619.         mov word ptr [ di ], '*.'
  620.         mov byte ptr [ di+2 ], 0
  621.  
  622. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  623. ;  rebuild and edit name
  624. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  625.  
  626. _dir_36:
  627.         lea si, offset [ _expandedname ][ bp ]
  628.         lea di, offset [ _pathname ][ bp ]
  629.         call _makePath
  630.  
  631.         lea si, offset [ _pathname ][ bp ]
  632.         lea di, offset [ _filename ][ bp ]
  633.         mov word ptr [ di ], '\'                        ; init area
  634.         Int21 GetActualFileName                         ; expand name to get real display name
  635.         jnc _dir_38                                     ; if ok -->
  636.  
  637.         lea si, offset [ _pathname ][ bp ]
  638.         lea di, offset [ _filename ][ bp ]
  639.         call _CopyString
  640.  
  641. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  642. ;  extract drive letter
  643. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  644.  
  645. _dir_38:
  646.         lea di, offset [ _filename ][ bp ]
  647.         cmp byte ptr [ di+1 ], ':'
  648.         jnz _dir_42
  649.  
  650.         xor ah, ah
  651.         mov al, byte ptr [ di ]
  652.         mov word ptr [ _currdisk ][ bp ], ax            ; save current disk
  653.  
  654. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  655. ;  display header
  656. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  657.  
  658. _dir_42:
  659.         test word ptr [ _DirBareSwitch. swFlags ], SW_SWITCHSET
  660.         jnz _dir_52                                     ; skip header  -->
  661.  
  662.         mov bx, offset _Dir_NoVolumeLabel               ; assume no volume label
  663.         mov al, byte ptr [ _currdisk ][ bp ]            ; get current disk value
  664.         call returnVolumeName                           ; get volume for drive
  665.         ifc _dirError                                   ; cannot open drive -->
  666.         jnz _dir_44                                     ; if no volume name -->
  667.  
  668.         push di                                         ; save vol label pointer
  669.         mov bx, offset _Dir_VolumeLabel                 ; print statement format
  670.  
  671. _dir_44:
  672.         lea di, offset [ _currdisk ][ bp ]              ; pointer to current disk
  673.         push di                                         ; current disk
  674.         push bx                                         ; format
  675.         lea di, offset [ _printbuffer ][ bp ]
  676.         push di
  677.         call _sprintf
  678.         add sp, ax                                      ; # args passed
  679.         call DisplayLine
  680.  
  681. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  682. ;  display drive: path
  683. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  684.  
  685.         lea si, offset [ _filename ][ bp ]
  686.         lea di, offset [ _pathname ][ bp ]
  687.         call _copyString                                ; copy to pathname
  688.  
  689. _dir_48:
  690.         dec di                  
  691.         cmp byte ptr [ di ], '\'                        ; isolate path
  692.         jnz _dir_48
  693.  
  694.         mov byte ptr [ di ], 0
  695.  
  696.         lea di, offset [ _pathname ][ bp ]
  697.         push di                                         ; first arg encountered
  698.  
  699.         mov di, offset _Dir_DirectoryOf
  700.         push di
  701.         lea di, offset [ _printbuffer ][ bp ]
  702.         push di
  703.         call _sprintf
  704.         add sp, ax                                      ; # args passed
  705.         call DisplayLine
  706.  
  707. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  708. ;  scan through files
  709. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  710.  
  711. _dir_52:
  712.         mov cx, ATTR_DIRECTORY
  713.         lea dx, offset [ _filename ][ bp ]              ; pointer to search filename
  714.         Int21 FindFirstFile                             ; locate file
  715.         ifc _dir_72                                     ; if none located -->
  716.  
  717. _dir_54:
  718.         inc word ptr [ _filesread ][ bp ]               ; files read
  719.  
  720.         mov ax, word ptr [ RxDOS_DTA. findFileTime ]
  721.         lea di, offset [ _asciiFileTime ][ bp ]
  722.         call _dirTimeToAscii
  723.         push di
  724.  
  725.         mov ax, word ptr [ RxDOS_DTA. findFileDate ]
  726.         lea di, offset [ _asciiFileDate ][ bp ]
  727.         call _dirDateToAscii
  728.         push di
  729.  
  730.         test byte ptr [ RxDOS_DTA. findFileAttribute ], ATTR_DIRECTORY
  731.         ifnz _dir_60                                    ; if a directory -->
  732.  
  733.         mov di, offset [ RxDOS_DTA. findFileSize ]
  734.         mov ax, word ptr [ _low  ][ di ]
  735.         mov dx, word ptr [ _high ][ di ]
  736.         add word ptr [ _totalfilespace. _low  ][ bp ], ax
  737.         adc word ptr [ _totalfilespace. _high ][ bp ], dx
  738.  
  739.         push di                                         ; third arg: file size
  740.  
  741. _dir_60:
  742.         mov di, offset [ RxDOS_DTA. findFileName ]      ; locate extension
  743.         mov al, byte ptr [ di ]                         ; start of filename
  744.         call _endofString                               ; point to null terminator
  745.  
  746.         push di                                         ; terminator, in case no extension
  747.         cmp al, '.'                                     ; filename either . or .. ?
  748.         jz _dir_64                                      ; yes, no need to find extension -->
  749.  
  750.         mov al, '.'
  751.         mov cx, offset [ RxDOS_DTA. findFileName ]      ; search length
  752.         xchg di, cx                                     ; determine search length
  753.         sub cx, di                                      ; search length
  754.         repnz scasb                                     ; else scan for extension
  755.         jnz _dir_64                                     ; if found, di points to extension
  756.         mov byte ptr [ di-1 ], 0                        ; else, di will point to a null (no extension)
  757.         pop ax
  758.         push di                                         ; extension address, if found
  759.  
  760. _dir_64:
  761.         mov di, offset [ RxDOS_DTA. findFileName ]
  762.         push di                                         ; pointer to filename
  763.  
  764.         mov di, offset _Dir_FileEntry
  765.         test byte ptr [ RxDOS_DTA. findFileAttribute ], ATTR_DIRECTORY
  766.         ifz _dir_66                                     ; if not a directory -->
  767.  
  768.         mov di, offset _Dir_DirEntry
  769.  
  770. _dir_66:
  771.         push di
  772.         lea di, offset [ _printbuffer ][ bp ]
  773.         push di
  774.         call _sprintf
  775.         add sp, ax                                      ; # args passed
  776.  
  777.         test word ptr [ _DirLowerCaseSwitch. swFlags ], SW_SWITCHSET
  778.         jz _dir_68                                      ; not lower case option ->
  779.         push ss
  780.         push si                                         ; where string
  781.         call _lowerCaseString                           ; lowercase string
  782.  
  783. _dir_68:
  784.         call DisplayLine                                ; print line
  785.  
  786.         Int21 FindNextFile                              ; locate next file
  787.         ifnc _dir_54                                    ; if none located -->
  788.  
  789. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  790. ;  print number of files 
  791. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  792.  
  793. _dir_72:
  794.         cmp word ptr [ _filesread ][ bp ], 0000         ; any files read ?
  795.         jnz _dir_76                                     ; yes -->
  796.  
  797.         mov dx, offset CmndError_NoFilesFound
  798.         call DisplayLine                                ; file not found
  799.         jmp short _dir_86
  800.  
  801. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  802. ;  display files, space used, space free
  803. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  804.  
  805. _dir_76:
  806.         mov dl, byte ptr [ _expandedName. expDrive ][ bp ]
  807.         and dl, 15                                      ; drive
  808.         Int21 GetFreeDiskSpace
  809.  
  810.         mul cx                                          ; total space
  811.         mul bx
  812.         stordarg _freespace, dx, ax
  813.  
  814.         lea di, offset [ _freespace ][ bp ]
  815.         push di
  816.         lea di, offset [ _totalfilespace ][ bp ]
  817.         push di
  818.         lea di, offset [ _filesread ][ bp ]
  819.         push di
  820.  
  821.         mov di, offset _Dir_Files
  822.         push di
  823.         lea di, offset [ _printbuffer ][ bp ]
  824.         push di
  825.         call _sprintf
  826.         add sp, ax                                      ; # args passed
  827.         call DisplayLine                                ; print line
  828.  
  829. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  830. ;  done
  831. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  832.  
  833. _dir_86:
  834.         Return
  835.  
  836. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  837. ;  if error
  838. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  839.  
  840. _dirError:
  841.         mov dx, offset CmndError_InvalidDrive
  842.         call DisplayErrorMessage                        ; display message
  843.         Return
  844.  
  845. RxDOSCMD                        ENDS
  846.                                 END
  847.